/*
 * 版权所有 (C) 2001-2014 深圳市艾派应用系统有限公司。保留所有权利。
 * 版本：
 * 修改记录：
 *		1、2014-11-21，tfl创建。 
 */
package com.chinamobile.ln.ictenterprises.ui.activity;

import com.chinamobile.ln.ictenterprises.R;
import com.chinamobile.ln.ictenterprises.common.Constants;
import com.chinamobile.ln.ictenterprises.common.Controller;
import com.chinamobile.ln.ictenterprises.common.MainApplication;
import com.chinamobile.ln.ictenterprises.db.IDataBase;
import com.chinamobile.ln.ictenterprises.utils.NetUtil;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Bundle;
import android.widget.LinearLayout;
import android.widget.Toast;

@SuppressLint("HandlerLeak")
public class ParentActivity extends Activity
{
    protected Context context;
    protected Controller mHttpManager = null;
    protected IDataBase database;
    protected MainApplication app;
    protected Dialog dialog;
    protected LinearLayout btnMenu;// 打开/关闭菜单按钮
    protected SharedPreferences sharedPref;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
    }

    @Override
    protected void onDestroy()
    {
        super.onDestroy();
    }

    public void init(int layoutId)
    {
        context = this;
        app = MainApplication.getInstance();
        sharedPref = getSharedPreferences(Constants.LOGIN_SHAREDPREF,
            Context.MODE_PRIVATE);
        mHttpManager = Controller.getInstance();
        setContentView(layoutId);
        setupView();
        setupData();
    }

    protected void setupData()
    {

    }

    protected void setupView()
    {

    }

    public void showProgressDialog(String msg)
    {
        if (dialog != null && dialog.isShowing())
        {
            return;
        }
        showProgressDialog(R.string.notice, msg);
    }

    public void dismissProgressDialog()
    {
        if (dialog != null && dialog.isShowing())
        {
            dialog.dismiss();
        }
    }

    protected void showProgressDialog(int title, String msg)
    {
        dialog = new ProgressDialog(this);
        ((ProgressDialog) dialog)
            .setProgressStyle(ProgressDialog.STYLE_SPINNER);
        dialog.setTitle(title);
        dialog.setCanceledOnTouchOutside(false);
        ((ProgressDialog) dialog).setMessage(msg);
        if (null != dialog && !dialog.isShowing())
        {
            try
            {
                dialog.show();
            }
            catch (Exception e)
            {
                e.printStackTrace();
            }
        }
    }

    /** 网络检查 **/
    protected boolean checkNet(Context context)
    {
        if (NetUtil.UNCONNECTED == NetUtil.getNetType(context))
        {
            return false;
        }
        return true;
    }

    /**
     * 提示
     * @param msg
     */
    protected void showTip(int msg)
    {
        Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();
    }

    /** 获取版本号 **/
    protected String getVersionName()
    {
        PackageManager packageManager = getPackageManager();
        // getPackageName()是你当前类的包名，0代表是获取版本信息
        PackageInfo packInfo = null;
        try
        {
            packInfo = packageManager.getPackageInfo(getPackageName(), 0);
        }
        catch (NameNotFoundException e)
        {
            e.printStackTrace();
        }
        return packInfo.versionName;
    }
    
    protected int getVersionCode()
    {
        PackageManager packageManager = getPackageManager();
        // getPackageName()是你当前类的包名，0代表是获取版本信息
        PackageInfo packInfo = null;
        try
        {
            packInfo = packageManager.getPackageInfo(getPackageName(), 0);
        }
        catch (NameNotFoundException e)
        {
            e.printStackTrace();
        }
        return packInfo.versionCode;
    }
}
